<?php session_start();?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <LINK REL=StyleSheet HREF="maintenancePagesCSS.css" TYPE="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body onLoad="togglePWReset();">
    <center>
  <table width="1000" height="509" border="0" background="images/background.jpg">
          <tr>
            <th height="505" scope="col"><center>
              <h3><img src="images/TitleUpdateExistingUser.gif" alt="Update Existing User" width="514" height="67"></h3>
              <?php
        if($_GET['id'])
        {
            $pk = $_GET['id'];
            include "EmployeeDao.php";
            include "Datasource.php";
            include "Employee.php";
            $objEmployeeDAO = new EmployeeDao();
            $objDatasource = new Datasource("localhost", "theanykey", "root", "");
            $objEmployee = new Employee();
           $objEmployee = $objEmployeeDAO->getObject(&$objDatasource, $pk);
           $lastName = $objEmployee->getLastName();
           $firstName = $objEmployee->getFirstName();
           $userRole = $objEmployee->getRole();
           $loginID = $objEmployee->getLoginID();
        ?>
              <form method="post" action="EditEmployeeFunct.php" id="frmPostEmployee">
                <table class="EditTable">
                  <tr>
                    <th align="right">*Last Name:&nbsp;&nbsp; </th>
                    <td><input type="text" id="txtEmployeeLastName" value="<?php echo $lastName; ?>" name="txtEmployeeLastName"  maxlength="45"/>                    </td>
                  </tr>
                  <tr>
                    <th align="right">*First Name:&nbsp;&nbsp; </th>
                    <td><input type="text" id="txtEmployeeFirstName" value="<?php echo $firstName;?>" name="txtEmployeeFirstName" maxlength="45" />                    </td>
                  </tr>
                  <tr>
                    <th align="right">*Login ID:&nbsp;&nbsp; </th>
                    <td><input type="text" id="txtLoginID" value="<?php echo $loginID;?>" name="txtLoginID" maxlength="15"/>                    </td>
                  </tr>
                  <tr>
                    <th align="right"> *Role:&nbsp;&nbsp; </th>
                    <td><select name="selRole" id="selRole">
                        <option
                    <?php
                    if($userRole == "User")
                    {
                        echo "Selected";
                    }
                    ?> value="User"
                    >User</option>
                        <option
                    <?php
                    if($userRole == "Admin")
                    {
                        echo "Selected";
                    }
                    ?> value="Admin"
                    >Admin</option>
                      </select>                    </td>
                  </tr>
                  <tr id="trPW1">
                    <th align="right">*Password:&nbsp;&nbsp; </th>
                    <td><input type="password" id="txtEmployeePwd" value="<?php echo $pw ?>" name="txtEmployeePwd" maxlength="25" />                    </td>
                  </tr>
                  <tr id="trPW2">
                    <th align="right">*Confirm Password:&nbsp;&nbsp; </th>
                    <td><input type="password" id="txtEmployeePwdConfirm" value="<?php echo $pw ?>" name="txtEmployeePwdConfirm" maxlength="25"/>                    </td>
                  </tr>
                </table>
                <table>
                  <tr>
                    <td width="50%"></td>
                    <td align="center"> Reset PW: &nbsp;
                        <input name="checkbox" type="checkbox" id="chkBxPWReset" onClick="togglePWReset();" />                    </td>
                  </tr>
                </table>
                <p><br />
                  <input name="button" type="button" onClick="submitUpdate();" value="Submit" />
                  <input type="hidden" value="<?php print $pk; ?>" name="PK">
                </p>
                <p><font style="font-style: italic; font-size: smaller">*denotes a required field</font> </p>
              </form>
            </center>
              <?php
        }
        else
        {
            print("<span style='color: Red'>There was an error accessing the information..."
            . "<br/>Please go back and try again.<br><i>If the problem persists, contact your system administrator...</i></span>");
        }
        ?>
              <br/>
              <center>
                <script src="links.js" language="javascript" type="text/javascript"></script>
                <script type="text/javascript">
            writeEmployeeLinks("", "");
              </script>
                <br>
                <br>
              </center></th>
          </tr>
        </table>
      <h3>&nbsp;</h3>
    </center>
        </body>
        <script type="text/javascript">

            function submitUpdate()
            {
                pwreset = document.getElementById("chkBxPWReset").checked;
                var strCorrect = "Please correct the following errors:\n";
                var strCompare = strCorrect;
                if(pwreset)
                {
                    strCorrect += checkPW();
                }
                strCorrect += checkFields();
                if(strCorrect == strCompare)
                {
                   document.getElementById("frmPostEmployee").submit();
                }
                else
                {
                    alert(strCorrect);
                }
            }
            function togglePWReset()
            {
                if(document.getElementById("chkBxPWReset").checked)
                {
                    document.getElementById("trPW1").style.display = "";
                    document.getElementById("trPW2").style.display = "";
                    document.getElementById("txtEmployeePwd").select();
                    document.getElementById("txtEmployeePwd").select();
                }
                else
                {
                    document.getElementById("trPW1").style.display = "none";
                    document.getElementById("trPW2").style.display = "none";
                    document.getElementById("txtEmployeeLastName").focus();
                }
            }
            function checkPW()
        {
            var pw1 = document.getElementById("txtEmployeePwd");
            var pw2 = document.getElementById("txtEmployeePwdConfirm");
            if(pw1.value != pw2.value)
            {
                return  "  - Passwords do not match\n";
            }
            else
            {
                return "";
            }
        }
        function checkFields()
        {
            var str = "";

            str += (document.getElementById("txtEmployeeLastName").value == "") ? "  - Last Name is Blank\n" : "";

            str += (document.getElementById("txtEmployeeFirstName").value == "") ? "  - First Name is Blank\n" : "";

            str += (document.getElementById("txtLoginID").value == "") ? "  - User ID is Blank\n" : "";

            if(pwreset)
            {
                str += (document.getElementById("txtEmployeePwd").value == "") ? "  - Password is Blank\n" : "";

                str += (document.getElementById("txtEmployeePwdConfirm").value == "") ? "  - Confirm Password is Blank\n" : "";

                str += (document.getElementById("txtEmployeePwd").value.length < 5) ? "  - Passwords must be at least five chararacters long\n" : "";
            }

            return str;
        }
        </script>
</html>
